package com.sc.VenusQueryBeta.adapter.account.daikuan;

import android.graphics.Color;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.hengjun.kingstar.sdk.utils.StringUtils;
import com.sc.VenusQueryBeta.R;
import com.sc.VenusQueryBeta.adapter.BaseCompatAdapter;
import com.sc.VenusQueryBeta.model.bean.account.daikuan.DaiKuanBean02;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2018/10/18.
 */

public class DaiKuanAdapter02 extends BaseCompatAdapter<DaiKuanBean02.DaiKuanList, BaseViewHolder> {
    private String roomname;

    public DaiKuanAdapter02(int layoutResId, @Nullable List<DaiKuanBean02.DaiKuanList> data, String roomname) {
        super(layoutResId, data);
        this.roomname = roomname;
    }

    public DaiKuanAdapter02(int item_daikuan02) {
        super(item_daikuan02);
    }


    @Override
    protected void convert(BaseViewHolder helper, DaiKuanBean02.DaiKuanList item) {
        helper.setText(R.id.tv_username_daikuan, item.getClientid());//户口
        helper.setText(R.id.daikuan_danhao, item.getFormid());//单号
        helper.setText(R.id.tv_jyje, StringUtils.FormatNumber(item.getLoannum()) + "萬");//交易金额

        //贷款时间
        String year = item.getModifytime().substring(0, 4);
        String month = item.getModifytime().substring(4, 6);
        String day = item.getModifytime().substring(6, 8);
        String hour = item.getModifytime().substring(8, 10);
        String min = item.getModifytime().substring(10);
        String date = year + "-" + month + "-" + day + " " + hour + ":" + min;
        helper.setText(R.id.tv_daikuan_time, date);
        //到期时间
        String year1 = item.getExpireddate().substring(0, 4);
        String month1 = item.getExpireddate().substring(4, 6);
        String day1 = item.getExpireddate().substring(6, 8);
        String hour1 = item.getExpireddate().substring(8, 10);
        String min1 = item.getExpireddate().substring(10);
        String date1 = year1 + "-" + month1 + "-" + day1 + " " + hour1 + ":" + min1;
        helper.setText(R.id.tv_daoqi_time, date1);

        //是否顯示小圖標
        TextView money = helper.getView(R.id.tv_jyje);
        TextView daikuantime = helper.getView(R.id.tv_daikuan_time);
        TextView daoqi = helper.getView(R.id.tv_daoqi_time);
        ImageView imageView = helper.getView(R.id.iv_daikuan);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date curDate = new Date(System.currentTimeMillis());
        String str = formatter.format(curDate);
        LogUtils.e("sasda=====" + str);
        int result = str.compareTo(date1);
        if (result < 0) {
            imageView.setImageDrawable(mContext.getResources().getDrawable(R.drawable.img_daikuan_wait));
            money.setTextColor(Color.WHITE);
            daoqi.setTextColor(Color.WHITE);
            daikuantime.setTextColor(Color.WHITE);
        } else {
            imageView.setImageDrawable(mContext.getResources().getDrawable(R.drawable.img_daikuan_over));
            money.setTextColor(Color.RED);
            daoqi.setTextColor(Color.RED);
            daikuantime.setTextColor(Color.RED);
        }
    }
}
